<template>
  <div>
    <div>
      action
    </div>
    <div id="demo">
      <button v-on:click="show = !show" style="background-color: red">
        Toggle
      </button>
      <transition name="fade" mode="out-in">
        <p v-if="show">hello</p>
      </transition>
      <transition name="fade">
        <p v-show="show">hello</p>
      </transition>
    </div>
    <div id="example-1">
      <transition
        name="slide-fade"
        :duration="{ enter: 500, leave: 800 }"
        v-on:before-enter="myConsole('1')"
        v-on:enter="myConsole('2')"
        v-on:after-enter="myConsole('3')"
        v-on:enter-cancelled="myConsole('4')"

        v-on:before-leave="myConsole('5')"
        v-on:leave="myConsole('6')"
        v-on:after-leave="myConsole('7')"
        v-on:leave-cancelled="myConsole('8')">
        <p v-if="show">hello</p>
      </transition>
    </div>
  </div>
</template>

<script>
  import {myconsole} from '../../util/help'

  export default {
    name: "Action",
    model: {},
    props: {},
    data() {
      return {
        show: true
      }
    },
    computed: {},
    beforeCreate: function () {

    },
    created: function () {

    },
    beforeMount: function () {

    },
    mounted: function () {

    },
    updated: function () {

    },
    activated: function () {

    },
    deactivated: function () {

    },
    beforeDestroy: function () {

    },
    destroyed: function () {

    },
    methods: {
      myConsole: myconsole
    },
    beforeRouteEnter(to, from, next) {
      // 在渲染该组件的对应路由被 confirm 前调用
      // 不！能！获取组件实例 `this`
      // 因为当守卫执行前，组件实例还没被创建
      console.log('beforeRouteEnter 是支持给 next 传递回调的唯一守卫')
      next()
    },
    beforeRouteUpdate(to, from, next) {
      // 在当前路由改变，但是该组件被复用时调用
      // 举例来说，对于一个带有动态参数的路径 /foo/:id，在 /foo/1 和 /foo/2 之间跳转的时候，
      // 由于会渲染同样的 Foo 组件，因此组件实例会被复用。而这个钩子就会在这个情况下被调用。
      // 可以访问组件实例 `this`
      console.log('beforeRouteUpdate hahahhahahahahahahahahhaah')
      next()
    },
    beforeRouteLeave(to, from, next) {
      // 导航离开该组件的对应路由时调用
      // 可以访问组件实例 `this`
      console.log('beforeRouteLeave')
      const answer = window.confirm('Do you really want to leave? you have unsaved changes!')
      if (answer) {
        next()
      } else {
        next(false)
      }
    }
    // data() {
    //   return {
    //     show: true
    //   }
    // },
    // methods: {
    //   myConsole: myConsole
    // }
  }
</script>

<style scoped>
  /*.fade-enter-active, .fade-leave-active {*/
  /*  transition: opacity .5s;*/
  /*}*/

  /*.fade-enter, .fade-leave-to !* .fade-leave-active below version 2.1.8 *!*/
  /*{*/
  /*  opacity: 0;*/
  /*}*/

  /*!* 可以设置不同的进入和离开动画 *!*/
  /*!* 设置持续时间和动画函数 *!*/
  /*.slide-fade-enter-active {*/
  /*  transition: all .3s ease;*/
  /*}*/

  /*.slide-fade-leave-active {*/
  /*  transition: all .8s cubic-bezier(1.0, 0.5, 0.8, 1.0);*/
  /*}*/

  /*.slide-fade-enter, .slide-fade-leave-to*/
  /*  !* .slide-fade-leave-active for below version 2.1.8 *!*/
  /*{*/
  /*  transform: translateX(10px);*/
  /*  opacity: 0;*/
  /*}*/


</style>
